package com.huawei.appgallery.wishwall.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ToggleButton;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
import java.util.ArrayList;
import java.util.List;
import o.ddq;
import o.ddq.c;
import o.ddq.d;
import o.ddu;
import o.dgp;

public class WishColumnNavigator extends LinearLayout implements OnClickListener, OnPageChangeListener {
    private LinearLayout ˊ;
    private String ˋ = "WishColumnNavigator";
    private ViewPager ˎ;
    private ToggleButton ˏ = null;
    private List<dgp> ॱ = new ArrayList();

    public WishColumnNavigator(Context context) {
        super(context);
        ˋ(context);
    }

    public WishColumnNavigator(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        ˋ(context);
    }

    public WishColumnNavigator(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˋ(context);
    }

    public void ˋ(Context context) {
        if (!isInEditMode()) {
            View inflate = View.inflate(getContext(), c.ˏॱ, null);
            this.ˊ = (LinearLayout) inflate.findViewById(d.ﹳ);
            addView(inflate, new LayoutParams(-1, -2));
        }
    }

    public int ˎ() {
        if (this.ˎ != null) {
            return this.ˎ.getCurrentItem();
        }
        return 0;
    }

    public void setViewPager(ViewPager viewPager) {
        this.ˎ = viewPager;
    }

    public void ॱ(dgp o_dgp) {
        if (o_dgp != null) {
            o_dgp.ॱ(this.ॱ.size());
            this.ॱ.add(o_dgp);
            ˎ(o_dgp);
        }
    }

    private void ˎ(dgp o_dgp) {
        ToggleButton toggleButton = (ToggleButton) LayoutInflater.from(getContext()).inflate(c.ͺ, null);
        ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
        layoutParams.topMargin = getContext().getResources().getDimensionPixelOffset(ddq.a.ˎ);
        layoutParams.bottomMargin = getContext().getResources().getDimensionPixelOffset(ddq.a.ˎ);
        layoutParams.setMarginEnd(getContext().getResources().getDimensionPixelOffset(ddq.a.ˎ));
        toggleButton.setLayoutParams(layoutParams);
        toggleButton.setOnClickListener(this);
        toggleButton.setTag(o_dgp);
        toggleButton.setText(o_dgp.ˊ());
        toggleButton.setTextOn(o_dgp.ˊ());
        toggleButton.setTextOff(o_dgp.ˊ());
        this.ˊ.addView(toggleButton);
    }

    public void ˏ(List<dgp> list) {
        if (list != null) {
            for (dgp ॱ : list) {
                ॱ(ॱ);
            }
        }
    }

    public void setCurrentItem(int i) {
        if (this.ˊ.getChildCount() > i) {
            onClick(this.ˊ.getChildAt(i));
        }
    }

    public void setCurrentItem(dgp o_dgp) {
        if (o_dgp != null && this.ˊ.getChildCount() > o_dgp.ॱ()) {
            onClick(this.ˊ.getChildAt(o_dgp.ॱ()));
        }
    }

    public void onClick(View view) {
        dgp o_dgp = (dgp) view.getTag();
        if (o_dgp != null) {
            ToggleButton toggleButton = (ToggleButton) view;
            toggleButton.setChecked(true);
            if (toggleButton != this.ˏ) {
                if (this.ˏ != null) {
                    this.ˏ.setChecked(false);
                }
                this.ˏ = toggleButton;
            }
            int ॱ = o_dgp.ॱ();
            this.ˎ.setCurrentItem(ॱ, true);
            ddu.ˊ.ˋ(this.ˋ, "WishColumnNavigator Button Pressed: " + ॱ);
        }
    }

    public void onPageScrolled(int i, float f, int i2) {
    }

    public void onPageScrollStateChanged(int i) {
        setCurrentItem(i);
    }

    public void onPageScrolled(int i) {
    }
}
